home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / term-source.lha / OwnDevUnit.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  1KB  |  67 lines

  1. /*
  2. **    OwnDevUnit.c
  3. **
  4. **    Device locking routines
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* Local copy of what we are locking */
  17.  
  18. STATIC UBYTE    DeviceName[MAX_FILENAME_LENGTH];
  19. STATIC LONG        UnitNumber = -1;
  20. STATIC BOOL        DeviceLocked = FALSE;
  21.  
  22. VOID
  23. UnlockDevice()
  24. {
  25.     if(DeviceLocked)
  26.     {
  27.         FreeDevUnit(DeviceName,UnitNumber);
  28.         DeviceLocked = FALSE;
  29.     }
  30. }
  31.  
  32. BOOL
  33. LockDevice(STRPTR Device,LONG Unit,STRPTR ErrorString,LONG ErrorStringSize)
  34. {
  35.     UnlockDevice();
  36.  
  37.     if(OwnDevUnitBase)
  38.     {
  39.         STRPTR Error;
  40.  
  41.         if(Error = AttemptDevUnit(Device,Unit,TermIDString,OwnDevBit))
  42.         {
  43.                 /* Check for the type of error, if any */
  44.  
  45.             if(ErrorString)
  46.             {
  47.                 if(!Strnicmp(Error,ODUERR_LEADCHAR,1))
  48.                     LimitedSPrintf(ErrorStringSize,ErrorString,LocaleString(MSG_SERIAL_ERROR_ACCESSING_TXT),Config->SerialConfig->SerialDevice,Config->SerialConfig->UnitNumber,&Error[1]);
  49.                 else
  50.                     LimitedSPrintf(ErrorStringSize,ErrorString,LocaleString(MSG_SERIAL_DEVICE_IN_USE_TXT),Config->SerialConfig->SerialDevice,Config->SerialConfig->UnitNumber,Error);
  51.             }
  52.  
  53.             return(FALSE);
  54.         }
  55.         else
  56.         {
  57.             LimitedStrcpy(sizeof(DeviceName),DeviceName,Device);
  58.  
  59.             UnitNumber = Unit;
  60.  
  61.             DeviceLocked = TRUE;
  62.         }
  63.     }
  64.  
  65.     return(TRUE);
  66. }
  67.